#import "HFFormLocalOptionTVC.h"
@implementation HFFormLocalOptionTVC
{
    UILabel             *_titleLabel;
    UILabel             *_contentLabel;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = UIColorFromRGB(0x555555);
        [self.contentView addSubview:_titleLabel];
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_contentLabel];
    }
    return self;
}
- (void)updateData:(HFFormRowModel *)row {
    [super updateData:row];
    _titleLabel.text = row.title;
    _contentLabel.text = (row.titleHandler && [row.titleHandler() length] > 0) ? row.titleHandler() : (row.content ? [NSString stringWithFormat:@"%@",row.content]: row.placeholder);
    _contentLabel.textColor = row.content ? UIColorFromRGB(0x222222) : UIColorFromRGB(0xe1e1e1);
    [self _constructData];
    NSMutableArray *array = @[].mutableCopy;
    for (NSInteger i = 0; i < row.subRows.count; i++) {
        HFFormRowModel *subRow = row.subRows[i];
        if (subRow.value) {
            BOOL find = NO;
            if (!find) {
                subRow.value = nil;
            }
        }else if (subRow.defaultSelectRow) {
            NSInteger j = subRow.defaultSelectRow.integerValue;
        }else{
        }
    }
    if (array.count > 0) {
        if (row.formatter) {
            NSString *formatter = row.formatter;
            if (array.count == 1) {
                self.row.content = [NSString stringWithFormat:formatter, array[0]];
            }else if(array.count == 2) {
                self.row.content = [NSString stringWithFormat:formatter, array[0], array[1]];
            }else if (array.count == 3) {
                self.row.content = [NSString stringWithFormat:formatter, array[0], array[1], array[2]];
            }else if (array.count == 4) {
                self.row.content = [NSString stringWithFormat:formatter, array[0], array[1], array[2], array[3]];
            }
        }else{
            self.row.content = [array componentsJoinedByString:@" "];
        }
        _contentLabel.textColor = UIColorFromRGB(0x222222);
    }
}
- (void)_constructData {
    if (self.row.subRows.count > 0) {
        for (long i = 0; i < self.row.subRows.count; i++) {
            HFFormRowModel *row  = self.row.subRows[i];
            NSArray *datas = row.multiDatas;
            row.valueHandler = ^(id value) {
                if (self.row.valueHandler) {
                    self.row.valueHandler(value);
                }
            };
            NSMutableArray *multiDatas = @[].mutableCopy;
            if(multiDatas.count > 0) row.multiDatas = multiDatas;
        }
    }
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _titleLabel.left    = 16;
    _titleLabel.top     = 12;
    _titleLabel.width   = self.width - _titleLabel.left - 50;
    _titleLabel.height  = 24;
    _contentLabel.left      = _titleLabel.left;
    _contentLabel.top       = 38;
    _contentLabel.width     = _titleLabel.width;
    _contentLabel.height    = 28;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
@end
